import sys
sys.path.insert(0, "/home/lighthouse/my-dream")

def weather_menu():
    from middle_script import save_file
    from entrance import main_entran
    from weather_api import Weather
    input_num = input("欢迎来到旅游信息系统\n请输入您想要进行的操作\n"
          "1. 查询当地天气\n2. 查询当地机场\n3.查询当地旅游景点\n4.返回主菜单")
    if input_num == "1":
        city_name = input("请输入想要前往的城市")
        # 获取城市的天气code
        city_id = save_file().read_txt(city_name=city_name)
        weathers = Weather().get_weather(city_id=city_id)
        # 遍历各个区天气信息
        for weather in weathers["data"]["relatedArea"]:
            final_info = weather["namecn"] + " 天气： " + weather["weather_pm"] + " 最高温度：" +\
                         weather["temperature_am"] + "最低温度：" + weather["temperature_pm"]
            print(final_info)
        wait = input("返回主菜单/退出程序(y/n)")
        if wait == "n":
            sys.exit(0)
        elif wait == "y":
            main_entran()
    if input_num == "2":
        city_name = input("请输入想要前往的城市")
        # 获取城市的天气code
        city_id = save_file().read_txt(city_name=city_name)
        weathers = Weather().get_weather(city_id=city_id)
        # 遍历各个区天气信息
        for weather in weathers["data"]["relateJc"]:
            final_info = " 机场： " + weather["namecn"] + " 天气: " + weather["weather_pm"] +\
                         " 温度： " + weather["temperature_am"]
            print(final_info)
        wait = input("返回主菜单/退出程序(y/n)")
        if wait == "n":
            sys.exit(0)
        elif wait == "y":
            main_entran()
    if input_num == "3":
        city_name = input("请输入想要前往的城市")
        # 获取城市的天气code
        city_id = save_file().read_txt(city_name=city_name)
        weathers = Weather().get_weather(city_id=city_id)
        # 遍历各个区天气信息
        for weather in weathers["data"]["related3Ajq"]:
            final_info = weather["namecn"] + " 天气： " + weather["weather_pm"] + \
                         " 温度： " + weather["temperature_am"]
            print(final_info)
        wait = input("返回主菜单/退出程序(y/n)")
        if wait == "n":
            sys.exit(0)
        elif wait == "y":
            main_entran()
    if input_num == "4":
        from entrance import main_entran
        main_entran()
    else:
        print("请输入正确的值")
        weather_menu()